/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package specifications;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Locale;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.nodes.Tag;

/**
 *
 * @author Jason
 */
public class TargetLanguage extends Parameter implements YamlObject<TargetLanguage> {
    public static final Tag TAG = new Tag("!TargetLanguage");
    private String language;
    private String region;
    private ArrayList<Directive> targetTerminology;
    
    
    public TargetLanguage(){}
    public TargetLanguage(String language, String region, ArrayList<Directive> terms){
        setPriority(20); //This is actually only the default for the targetTerminology
        this.region = region;
        this.language = language;
        this.targetTerminology = terms;
        
    }
    
    @Override
    public ArrayList<Directive> getDirectives() {
        Locale locale = new Locale(getLanguage(), getRegion());
        ArrayList<Directive> out = new ArrayList<Directive>(targetTerminology);
        out.add(0, new ProviderDirective("The target text is appropriate for readers in " + locale.getDisplayCountry()+".", 10));
        out.add(0, new ProviderDirective("The target text is written in "+locale.getDisplayLanguage()+".", 50));
        return out;
    }

    @Override
    public void dump(String filename) throws IOException {
        Yaml yaml = new Yaml(CONSTRUCTOR, REPRESENTER);
        FileWriter writer = new FileWriter(filename);
        writer.write(yaml.dumpAs(this, TAG, DumperOptions.FlowStyle.BLOCK));
        writer.close();
    }

    @Override
    public TargetLanguage load(String filename) throws IOException {
        Yaml yaml = new Yaml(CONSTRUCTOR, REPRESENTER);
        FileReader reader = new FileReader(filename);
        TargetLanguage param = yaml.loadAs(reader, TargetLanguage.class);
        reader.close();
        return param;
    }


    /**
     * @return the language
     */
    public String getLanguage() {
        return language;
    }

    /**
     * @param language the language to set
     */
    public void setLanguage(String language) {
        this.language = language;
    }

    /**
     * @return the region
     */
    public String getRegion() {
        return region;
    }

    /**
     * @param region the region to set
     */
    public void setRegion(String region) {
        this.region = region;
    }

    /**
     * @return the targetTerminology
     */
    public ArrayList<Directive> getTargetTerminology() {
        return targetTerminology;
    }

    /**
     * @param targetTerminology the targetTerminology to set
     */
    public void setTargetTerminology(ArrayList<Directive> targetTerminology) {
        this.targetTerminology = targetTerminology;
    }
    
}
